
/**
 * AjaxProxy用户通过Ajax提交表单
 * author:huangjie
 * time:2010.6.24  
 */
$ap = AjaxProxy.prototype
var xmlHttp = false;
function AjaxProxy(serverName){
	this.request = "*.AJAX";
	if (serverName != null && serverName != null) {
		this.request = serverName;		
	}
	this.parameter = "";
	this.responseValue = null;
}

$ap.addParm = function(para_Name,para_Value){
	if(para_Value != null){
		para_Value += "";		
		para_Value = para_Value.replace(/%/g  ,"%25");
		para_Value = para_Value.replace(/&/g  ,"%26");
		para_Value = para_Value.replace(/\+/g  ,"%2B");
		para_Value = para_Value.replace(/\?/g ,"%3F");
		this.parameter += "&" + para_Name + "=" + para_Value;
	}
}
//url:
//asyn:true/false 
//proxy:AjaxProxy对象
//callback:
$ap.invoke = function (url,asyn,proxy,callback){
	if(url == null || url == ""){
		alert("\u8bf7\u6c42\u65e0\u6548!")
		return;
	}else{
		this.parameter = this.parameter.substring(this.parameter.indexOf('&')+1);
		url += "";		
		url = url.replace(/%/g  ,"%25");
		url = url.replace(/&/g  ,"%26");
		url = url.replace(/\+/g  ,"%2B");
		url = url.replace(/\?/g ,"%3F");
		this.parameter = "SERVICENAME=" + url + "&" + this.parameter;
	}
	if(asyn == null){
		asyn = false;
	}
	var lobj_xmlHttp = null; 
	try{
		lobj_xmlHttp = new XMLHttpRequest();
	}catch(e){
		try{
			lobj_xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");				
		}catch(e){
			try{
				lobj_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");			
			}catch(e){	
				this.xmlHttp = false;
				return;
			}
		}
	}

	lobj_xmlHttp.open("POST",this.request,asyn);
	lobj_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	if(asyn){
		
		lobj_xmlHttp.onreadystatechange = function (){
			if(lobj_xmlHttp.readyState == 4){
				if(lobj_xmlHttp.status == 200){
					var res = lobj_xmlHttp.responseText
					try{
						proxy.responseValue = eval('(' + res + ')');
					}catch(e){
						proxy.responseValue = res;
					}
					callback(proxy);
					lobj_xmlHttp = void(0);
				}
			}	
		}
		lobj_xmlHttp.send(this.parameter);
	}else{
		lobj_xmlHttp.send(this.parameter);
		
		var res = lobj_xmlHttp.responseText;
		try{
			this.responseValue = eval('(' + res + ')');
		}catch(e){
			this.responseValue = res;
		}
		lobj_xmlHttp = void(0);
	}
}

$ap.getRowCount = function (){
	var arg = arguments.length;
	switch(arg){
		case 0:return this.responseValue.length;
		case 1:return this.responseValue[0][arguments[0]].length;
		default:return alert("\u53c2\u6570\u5217\u8868\u9519\u8bef");
	}
}

$ap.getString = function (){
	var arg = arguments.length;
	switch(arg){
		case 1:return this.responseValue[0][arguments[0]];
		case 2:return this.responseValue[arguments[0]][arguments[1]];
		case 3:return this.responseValue[0][arguments[0]][arguments[1]][arguments[2]];
		default:return alert("\u53c2\u6570\u5217\u8868\u9519\u8bef");
	}
}

$ap.getValue = function (){
	return this.responseValue;
}

$ap.getData = function (){
	return this.responseValue[0][arguments[0]];
}